package com.vote.www.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.vote.www.utils.SendMessageUtil;

@Controller
public class SengTestPhoneController extends BaseController {

	private static final Logger log = LoggerFactory
			.getLogger(SengTestPhoneController.class);

	@RequestMapping("sendPhonesPre")
	public String sendPhonesPre(HttpServletRequest request,
			HttpServletResponse response) {

		return "sendMessage";
	}

	@RequestMapping("sendPhones")
	public void sendPhones(@RequestParam(required = true) String type,
			HttpServletRequest request, HttpServletResponse response) {

		try {
			String phones = null;
			if (type.equals("1000")) {
				phones = "13925266710";
			} else if (type.equals("1001")) {
				phones = "15587754858,13620084061";
			} else if (type.equals("1002")) {
				phones = "13560121071,13506063415,18027986850,"
						+ "18565401468,13377619779,18666696110,13411239262,"
						+ "13592897051,13760264169,13822202065,18520618025,"
						+ "13076243241,13727586289,13922323467,18127936952,"
						+ "13430167672,13778715936,18127936952,13430167672,"
						+ "18813933055,18874751847,13631559653,15814033951,"
						+ "13192877002,15812586372,13590115172,18824140518";
			} else {
				jsonResult(0, "888", "没有你输入的类型:" + type, "", response);
				return;
			}

			HashMap<String, Object> result = SendMessageUtil.send(phones,
					response, request, type);

			if ("000000".equals(result.get("statusCode"))) {

				jsonResult(1, "109", "短信发送成功", result, response);
			} else {

				jsonResult(0, "110", "短信发送失败", result, response);

			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("短信群发失败", e);
		}

	}
}
